﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZF.BLL;
using GCELibrary.Current;

namespace ZF.WS.news
{
    public partial class fitup : BLL.Page.PageBase
    {
        public Model.I_News New { get; set; }

        public Model.I_News NewPrv { get; set; }
        public Model.I_News NewNext { get; set; }
        [PageArgument(Key = "id", CanNull = false)]
        public int id { get; set; }
        public int TypeId { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            using (var dc = SiteInfo.CreateDBDataContext())
            {
                var newinfo = dc.I_News.FirstOrDefault(p => p.NewsId == id);
                if (newinfo == null)
                {
                    throw WarnFactory.CreateWarn(WarnCode.ReocrdNoFind);
                }
                this.New = newinfo;
                NewPrv=dc.I_News.OrderByDescending(p => p.NewsId).Where(p => p.NewsId < id).FirstOrDefault();
                NewNext = dc.I_News.OrderBy(p => p.NewsId).Where(p => p.NewsId > id).FirstOrDefault();



            }

            using (var dc = SiteInfo.CreateDBDataContext())
            {

                List<object> list = null;

                var cacheKey = "news_index_JPLP";
                var obj = HttpCache.GetCache(cacheKey);
                if (obj != null)
                {
                    list = obj as List<object>;
                }
                else
                {
                    list = dc.H_Estate.Where(p => p.IsVerify)
                     .OrderByDescending(p => p.EstateId).Take(18).ToList().Select(p => (object)p).ToList();
                    SiteInfo.Instance.SetPageCache(cacheKey,list);
                }

            }


        }
    }
}
